package com.ruoyi.web.controller.mes;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.web.domain.vo.CareDetailVo;
import com.ruoyi.web.service.IMesMachineCareService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.mes.MesMachineCaredetail;
import com.ruoyi.web.service.IMesMachineCaredetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备保养记录Controller
 *
 * @author levicash
 * @date 2024-01-15
 */
@RestController
@RequestMapping("/mes/caredetail")
public class MesMachineCaredetailController extends BaseController {
    @Autowired
    private IMesMachineCaredetailService mesMachineCaredetailService;

    /**
     * 查询设备保养记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CareDetailVo careDetailVo) {
        startPage();
        //List<MesMachineCaredetail> list = mesMachineCaredetailService.selectMesMachineCaredetailList(mesMachineCaredetail);
        Map<String, Object> map = new HashMap<>();
        map.put("code", careDetailVo.getCode());
        map.put("status", careDetailVo.getStatus());
        map.put("planCode", careDetailVo.getPlanCode());
        map.put("machineName", careDetailVo.getMachineName());
        map.put("machineNo", careDetailVo.getMachineNo());
        map.put("mark", careDetailVo.getMark());
        List<CareDetailVo> list = mesMachineCaredetailService.selectMesMachineCaredetailAll(map);
        return getDataTable(list);
    }

    /**
     * 获取保报工保养记录
     */
    @GetMapping("/reportcarelist")
    public AjaxResult list(MesMachineCaredetail machineCaredetail) {
        Map<String, Object> map = new HashMap<>();
        map.put("reportCare", "ok"); // 报工关联维修保养详情，取今天的
        machineCaredetail.setParams(map);
        List<MesMachineCaredetail> list = mesMachineCaredetailService.selectMesMachineCaredetailList(machineCaredetail);
        return success(list);
    }


    /**
     * 导出设备保养记录列表
     */
    @Log(title = "设备保养记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesMachineCaredetail mesMachineCaredetail) {
        List<MesMachineCaredetail> list = mesMachineCaredetailService.selectMesMachineCaredetailList(mesMachineCaredetail);
        ExcelUtil<MesMachineCaredetail> util = new ExcelUtil<MesMachineCaredetail>(MesMachineCaredetail.class);
        util.exportExcel(response, list, "设备保养记录数据");
    }

    /**
     * 获取设备保养记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mesMachineCaredetailService.selectMesMachineCaredetailById(id));
    }

    /**
     * 新增设备保养记录
     */
    @Log(title = "设备保养记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesMachineCaredetail mesMachineCaredetail) {
        // mesMachineCareService.c
        return toAjax(mesMachineCaredetailService.insertMesMachineCaredetail(mesMachineCaredetail));
    }

    /**
     * 修改设备保养记录
     */
    @Log(title = "设备保养记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesMachineCaredetail mesMachineCaredetail) {
        return toAjax(mesMachineCaredetailService.updateMesMachineCaredetail(mesMachineCaredetail));
    }

    /**
     * 删除设备保养记录
     */
    @Log(title = "设备保养记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mesMachineCaredetailService.deleteMesMachineCaredetailByIds(ids));
    }
}
